// hyb_yl/czhuanjiasubpages/pages/questions/index.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tel: ""
  },
  getel: function(e) {
    this.setData({
      tel: e.detail.value
    })
    console.log(this.data.tel)
  },
  nextpage: function() {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.keywords
    var j_id = that.data.j_id
    let modul = wx.getStorageSync('modul')
    let msglist = JSON.parse(modul)
    if (that.data.tel) {
      //生成订单
      app.util.request({
        'url': 'entry/wxapp/hzbingli.addbingli',
        data: {
          msglist: msglist,
          sicktel: that.data.tel,
          openid: wx.getStorageSync('openid'),
          j_id: j_id,
          keywords: keywords
        },
        success: function(res) {
          console.log(res)
          var bl_id = res.data
          //插入问诊订单
          var name = that.data.name
          app.util.request({
            'url': 'entry/wxapp/hzbingli.addorder',
            data: {
              zid: zid,
              name: name,
              keywords: keywords,
              openid: wx.getStorageSync('openid'),
              bl_id: bl_id,
              money: that.data.newmoney,
              j_id: j_id
            },
            success: function(res) {
              console.log(res)
              var name = res.data.name
              var order = res.data.order
              var money = res.data.money
              wx.navigateTo({
                url: '/hyb_yl/czhuanjiasubpages/pages/questends/index?phone=' + that.data.tel + '&zid=' + zid + '&name=' + name + '&keywords=' + keywords + '&j_id=' + j_id + '&allone_key=1' + '&name=' + name + '&order=' + order + '&money=' + money
              })
            }
          })
        }
      })
    } else {
      wx.showToast({
        title: '请输入有效号码',
        icon: "none"
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    var name = options.name
    var keywords = options.keywords
    var j_id = options.j_id
    var tel = options.tel
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.docinfo',
      data: {
        zid: zid,
        key: keywords,
      },
      success: function(res) {
        that.setData({
          newmoney: res.data.data.newmoney
        })
      }
    })
    that.setData({
      trandatas: options,
      zid: zid,
      name: name,
      keywords: keywords,
      j_id: j_id,
      tel: tel
    })
    // console.log(this.data.trandatas)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})